package com.jinzecloud.reportapproval.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jinzecloud.reportapproval.bean.VegetationRecordForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jinzecloud.reportapproval.bean.BreakageRate;
import com.jinzecloud.reportapproval.service.BreakageRateService;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;



/**
 * 碎土率测定记录表
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-12-09 12:16:45
 */
@RestController
@RequestMapping("reportapproval/breakagerate")
public class BreakageRateController {
    @Autowired
    private BreakageRateService breakageRateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("reportapproval:breakagerate:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = breakageRateService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("reportapproval:breakagerate:info")
    public R info(@PathVariable("id") Integer id){
		BreakageRate breakageRate = breakageRateService.getById(id);

        return R.ok().put("breakageRate", breakageRate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("reportapproval:breakagerate:save")
    public R save(@RequestBody BreakageRate breakageRate){

        List<BreakageRate> projectCode = breakageRateService.list(new QueryWrapper<BreakageRate>().eq("project_code", breakageRate.getProjectCode()));
        if (projectCode.size() > 0) return R.error("编号："+breakageRate.getProjectCode()+"已存在，请勿重复添加！");

		breakageRateService.save(breakageRate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("reportapproval:breakagerate:update")
    public R update(@RequestBody BreakageRate breakageRate){
		breakageRateService.updateById(breakageRate);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("reportapproval:breakagerate:delete")
    public R delete(@RequestBody Integer[] ids){
		breakageRateService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/viewPdf/{id}")
    public String viewPdf(@PathVariable("id") Integer id){
        return breakageRateService.viewPdf(id);
    }

}
